import neu.soft.SubWarehouseApplication1050;
import neu.soft.message.MessageSource;
import neu.soft.vo.MsgBean;
import org.apache.rocketmq.common.message.MessageConst;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.MimeTypeUtils;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SubWarehouseApplication1050.class)
public class testMsg {

    @Autowired
    private MessageSource source;
    public <T> boolean confirmPurchaseIn(T msg, Integer delay){
        Message<T> message = MessageBuilder.withPayload(msg)
                .setHeader(MessageConst.PROPERTY_DELAY_TIME_LEVEL, delay)
                .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
                .build();
        System.out.println(message);
        return source.confirmPurchaseIn().send(message);
    }


    @Test
    public void testSendMsg(){
        String orderId ="bfd94600260211ee81a75c3a45dad1b2";
        this.confirmPurchaseIn(new MsgBean(orderId,"中心库房已购货入库"),0);
    }
}
